< previous page page_50 next page >

Page 50
you are working with early in the development cycle and can avoid propagating bugs throughout your code.
The RegOpenKeyEx function is used to open a registry key. The function is defined as follows in the API documentation:
LONG RegOpenKeyEx(
    HKEY hKey,                     // handle of open key
    LPCTSTR lpSubKey,              // address of name of subkey to open
    DWORD ulOptions,               // reserved
    REGSAM samDesired,             // security access mask
    PHKEY phkResult                // address of handle of open key
   );
The HKEY parameter is a handlea 32-bit Long value. You can find the following root constants in the api32.txt file on the CD that comes with this book:
Public Const HKEY_CLASSES_ROOT = &H80000000
Public Const HKEY_CURRENT_USER = &H80000001
Public Const HKE_LOCAL_MACHINE = &H80000002
Public Const HKEY_USERS = &H80000003
Public Const HKEY_PERFORMANCE_DATA = &H80000004
Public Const HKEY_CURRENT_CONFIG = &H80000005
The lpSubKey parameter is a string that specifies the subkey you want to open. In this case, it will be \SYSTEM\CurrentControlSet\Control.
The ulOptions parameter is reserved and should be set to 0.
The samDesired parameter is a Long value that specifies which access rights you wish. For example, you can specify the constant KEY_QUERY_VALUE if you wish to be able to read the values of a key. Your request is compared to the access rights that are permitted for the account under which the program is running. If the right you request is allowed, the request is granted and you will be able to perform the requested operation.
The phkResult parameter is a Long variable that will be loaded with the open key.
A separate function, RegCloseKey, is used to close the key when it is no longer needed.
As a first step, the following program attempts to open the Control key and reports on whether it succeeds:
' Reading Registry Keys
' Copyright © 1998 by Desaware Inc. All Rights Reserved

 
< previous page page_50 next page >